﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace B121 {
    public partial class AddNewItemForm : Form {
        public AddNewItemForm() {
            InitializeComponent();
        }
        #region Properties
         public List<ItemClass> Items { get; private set; }
        #endregion

        
        private void cancelBtn_Click(object sender, EventArgs e) {
            this.Close();
        }

        private void addNewItemBtn_Click(object sender, EventArgs e) {
            if (itemNameTxtBox.Text == "") {
                throw new ArgumentException("Items needs to have a name");
            } else {
                Items = new List<ItemClass>();
                for (int i = 1; i <= AccessData.TryToParseInt(numberOfItem.Value); i++) {
                    Items.Add(new ItemClass(itemNameTxtBox.Text + i,
                        AccessData.TryToParseInt(itemXNumBox.Value),
                        AccessData.TryToParseInt(itemYNumBox.Value),
                        AccessData.TryToParseInt(itemZNumBox.Value),
                        AccessData.TryToParseInt(itemWeightNumBox.Value)));
                }
            }
        }

        private void resetFieldsBtn_Click(object sender, EventArgs e) {
            itemNameTxtBox.Text = "";
            itemXNumBox.Value = 10;
            itemYNumBox.Value = 10;
            itemZNumBox.Value = 10;
            itemWeightNumBox.Value = 50;
            numberOfItem.Value = 1;
        }

        private void AddNewItemForm_Load(object sender, EventArgs e) {
            resetFieldsBtn.PerformClick();
        }

        private void itemNameTxtBox_TextChanged(object sender, EventArgs e) {
            addNewItemBtn.Enabled = (itemNameTxtBox.Text != "" ? true : false);
        }
    }
}
